<?php

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreatePostTagTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('post_tag', function (Blueprint $table) {
            $table->increments('id')->unsigned();
            $table->unsignedInteger('post_id')->nullable();
            $table->unsignedInteger('tag_id')->nullable();
            $table->timestamps();
//            $table->foreign('post_id')
//                ->references('id')
//                ->on('posts')
//                ->onUpdate('cascade')
//                ->onDelete('cascade');
//
//            $table->foreign('tag_id')
//                ->references('id')
//                ->on('tags')
//                ->onUpdate('cascade')
//                ->onDelete('cascade');
        });
        $driverName = Schema::getConnection()->getDriverName();
        if ('mysql' === $driverName) {
            DB::update(<<<END
                ALTER TABLE `comment`
                ENGINE=InnoDB,
                DEFAULT CHARACTER SET=utf8,
                AUTO_INCREMENT=100;
END
            );
        }

    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
//        Schema::table('post_tag', function(Blueprint $table){
//            $table->dropForeign('post_tag_post_id_foreign');
//            $table->dropForeign('post_tag_tag_id_foreign');
//        });
        Schema::dropIfExists('post_tag');
    }
}
